package Demo;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Setting extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;
    private JTextField OPENAI_TOKEN;
    private JTextField USER;
    private JComboBox MODEL;
    private JTextField MAX_TOKENS;
    private JTextField TOP_P;
    private JTextField TEMPERATURE;
    private JTextField BEST_OF;
    private JTextField SIZE;
    private JTextField N;

    public Setting() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

        buttonOK.addActionListener(e -> onOK());
        buttonCancel.addActionListener(e -> onCancel());
        // 点击 X 时调用 onCancel()
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });
        // 遇到 ESCAPE 时调用 onCancel()
        contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        OPENAI_TOKEN.setText(Utils.properties.getProperty("OPENAI_TOKEN"));
        USER.setText(Utils.properties.getProperty("USER"));
        MODEL.setSelectedItem(Utils.properties.getProperty("MODEL"));
        MAX_TOKENS.setText(Utils.properties.getProperty("MAX_TOKENS"));
        TOP_P.setText(Utils.properties.getProperty("TOP_P"));
        TEMPERATURE.setText(Utils.properties.getProperty("TEMPERATURE"));
        BEST_OF.setText(Utils.properties.getProperty("BEST_OF"));
        SIZE.setText(Utils.properties.getProperty("SIZE"));
        N.setText(Utils.properties.getProperty("N"));
    }

    private void onOK() {
        Utils.properties.setProperty("OPENAI_TOKEN", OPENAI_TOKEN.getText());
        Utils.properties.setProperty("USER", USER.getText());
        Utils.properties.setProperty("MODEL", (String) MODEL.getSelectedItem());
        Utils.properties.setProperty("MAX_TOKENS", MAX_TOKENS.getText());
        Utils.properties.setProperty("TOP_P", TOP_P.getText());
        Utils.properties.setProperty("TEMPERATURE", TEMPERATURE.getText());
        Utils.properties.setProperty("BEST_OF", BEST_OF.getText());
        Utils.properties.setProperty("SIZE", SIZE.getText());
        Utils.properties.setProperty("N", N.getText());
        Utils.save();
        dispose();
    }

    private void onCancel() {
        dispose();
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        contentPane = new JPanel();
        contentPane.setLayout(new GridBagLayout());
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new GridBagLayout());
        GridBagConstraints gbc;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        contentPane.add(panel1, gbc);
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel1.add(panel2, gbc);
        buttonOK = new JButton();
        buttonOK.setText("确定");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel2.add(buttonOK, gbc);
        buttonCancel = new JButton();
        buttonCancel.setText("取消");
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel2.add(buttonCancel, gbc);
        final JPanel panel3 = new JPanel();
        panel3.setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        contentPane.add(panel3, gbc);
        panel3.setBorder(BorderFactory.createTitledBorder(null, "", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JPanel panel4 = new JPanel();
        panel4.setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel3.add(panel4, gbc);
        panel4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "OPENAI_TOKEN（密钥）", TitledBorder.LEFT, TitledBorder.TOP, null, null));
        OPENAI_TOKEN = new JTextField();
        OPENAI_TOKEN.setColumns(30);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel4.add(OPENAI_TOKEN, gbc);
        final JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel3.add(panel5, gbc);
        panel5.setBorder(BorderFactory.createTitledBorder(null, "USER（密钥使用用户）", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        USER = new JTextField();
        USER.setColumns(30);
        USER.setEnabled(true);
        panel5.add(USER);
        final JPanel panel6 = new JPanel();
        panel6.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel3.add(panel6, gbc);
        panel6.setBorder(BorderFactory.createTitledBorder(null, "MODEL（模型）", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        MODEL = new JComboBox();
        MODEL.setEditable(true);
        final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel();
        defaultComboBoxModel1.addElement("文本编辑：");
        defaultComboBoxModel1.addElement("text-davinci-edit-001");
        defaultComboBoxModel1.addElement("code-davinci-edit-001");
        defaultComboBoxModel1.addElement("文本回复：");
        defaultComboBoxModel1.addElement("babbage");
        defaultComboBoxModel1.addElement("davinci");
        defaultComboBoxModel1.addElement("text-embedding-ada-002");
        defaultComboBoxModel1.addElement("babbage-code-search-code");
        defaultComboBoxModel1.addElement("text-similarity-babbage-001");
        defaultComboBoxModel1.addElement("text-davinci-001");
        defaultComboBoxModel1.addElement("curie-instruct-beta");
        defaultComboBoxModel1.addElement("babbage-code-search-text");
        defaultComboBoxModel1.addElement("babbage-similarity");
        defaultComboBoxModel1.addElement("curie-search-query");
        defaultComboBoxModel1.addElement("code-search-babbage-text-001");
        defaultComboBoxModel1.addElement("code-cushman-001");
        defaultComboBoxModel1.addElement("code-search-babbage-code-001");
        defaultComboBoxModel1.addElement("audio-transcribe-deprecated");
        defaultComboBoxModel1.addElement("text-ada-001");
        defaultComboBoxModel1.addElement("text-similarity-ada-001");
        defaultComboBoxModel1.addElement("text-davinci-insert-002");
        defaultComboBoxModel1.addElement("text-davinci-003");
        defaultComboBoxModel1.addElement("ada-code-search-code");
        defaultComboBoxModel1.addElement("ada-similarity");
        defaultComboBoxModel1.addElement("code-search-ada-text-001");
        defaultComboBoxModel1.addElement("text-search-ada-query-001");
        defaultComboBoxModel1.addElement("text-curie-001");
        defaultComboBoxModel1.addElement("text-davinci-edit-001");
        defaultComboBoxModel1.addElement("davinci-search-document");
        defaultComboBoxModel1.addElement("ada-code-search-text");
        defaultComboBoxModel1.addElement("text-search-ada-doc-001");
        defaultComboBoxModel1.addElement("code-davinci-002");
        defaultComboBoxModel1.addElement("code-davinci-edit-001");
        defaultComboBoxModel1.addElement("davinci-instruct-beta");
        defaultComboBoxModel1.addElement("text-similarity-curie-001");
        defaultComboBoxModel1.addElement("code-search-ada-code-001");
        defaultComboBoxModel1.addElement("ada-search-query");
        defaultComboBoxModel1.addElement("text-search-davinci-query-001");
        defaultComboBoxModel1.addElement("ada");
        defaultComboBoxModel1.addElement("davinci-search-query");
        defaultComboBoxModel1.addElement("text-davinci-insert-001");
        defaultComboBoxModel1.addElement("babbage-search-document");
        defaultComboBoxModel1.addElement("ada-search-document");
        defaultComboBoxModel1.addElement("text-search-babbage-doc-001");
        defaultComboBoxModel1.addElement("text-search-curie-doc-001");
        defaultComboBoxModel1.addElement("text-search-curie-query-001");
        defaultComboBoxModel1.addElement("babbage-search-query");
        defaultComboBoxModel1.addElement("text-babbage-001");
        defaultComboBoxModel1.addElement("text-search-davinci-doc-001");
        defaultComboBoxModel1.addElement("text-search-babbage-query-001");
        defaultComboBoxModel1.addElement("curie-similarity");
        defaultComboBoxModel1.addElement("curie-search-document");
        defaultComboBoxModel1.addElement("curie");
        defaultComboBoxModel1.addElement("text-similarity-davinci-001");
        defaultComboBoxModel1.addElement("text-davinci-002");
        defaultComboBoxModel1.addElement("davinci-similarity");
        defaultComboBoxModel1.addElement("cushman:2020-05-03");
        defaultComboBoxModel1.addElement("ada:2020-05-03");
        defaultComboBoxModel1.addElement("babbage:2020-05-03");
        defaultComboBoxModel1.addElement("curie:2020-05-03");
        defaultComboBoxModel1.addElement("davinci:2020-05-03");
        defaultComboBoxModel1.addElement("if-davinci-v2");
        defaultComboBoxModel1.addElement("if-curie-v2");
        defaultComboBoxModel1.addElement("if-davinci:3.0.0");
        defaultComboBoxModel1.addElement("davinci-if:3.0.0");
        defaultComboBoxModel1.addElement("davinci-instruct-beta:2.0.0");
        defaultComboBoxModel1.addElement("text-ada:001");
        defaultComboBoxModel1.addElement("text-davinci:001");
        defaultComboBoxModel1.addElement("text-curie:001");
        defaultComboBoxModel1.addElement("text-babbage:001");
        MODEL.setModel(defaultComboBoxModel1);
        MODEL.setToolTipText("文本编辑：\ntext-davinci-edit-001 \ncode-davinci-edit-001");
        MODEL.putClientProperty("html.disable", Boolean.FALSE);
        panel6.add(MODEL);
        final JPanel panel7 = new JPanel();
        panel7.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel3.add(panel7, gbc);
        panel7.setBorder(BorderFactory.createTitledBorder(null, "MAX_TOKENS（最大回复字数）", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        MAX_TOKENS = new JTextField();
        MAX_TOKENS.setColumns(30);
        panel7.add(MAX_TOKENS);
        final JPanel panel8 = new JPanel();
        panel8.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        panel3.add(panel8, gbc);
        panel8.setBorder(BorderFactory.createTitledBorder(null, "TOP_P（高概率下落比  0-1）", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        TOP_P = new JTextField();
        TOP_P.setColumns(30);
        TOP_P.setEditable(true);
        TOP_P.setText("");
        panel8.add(TOP_P);
        final JPanel panel9 = new JPanel();
        panel9.setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel3.add(panel9, gbc);
        panel9.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "TEMPERATURE（变异比 0-1）", TitledBorder.LEFT, TitledBorder.TOP, null, new Color(-16777216)));
        TEMPERATURE = new JTextField();
        TEMPERATURE.setColumns(30);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel9.add(TEMPERATURE, gbc);
        final JPanel panel10 = new JPanel();
        panel10.setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel3.add(panel10, gbc);
        panel10.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "BEST_OF( 生成的版本数）", TitledBorder.LEFT, TitledBorder.TOP, null, null));
        BEST_OF = new JTextField();
        BEST_OF.setColumns(30);
        BEST_OF.setText("");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel10.add(BEST_OF, gbc);
        final JPanel panel11 = new JPanel();
        panel11.setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel3.add(panel11, gbc);
        panel11.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "SIZE（图片大小  256x256, 512x512,1024x1024）", TitledBorder.LEFT, TitledBorder.TOP, null, null));
        SIZE = new JTextField();
        SIZE.setColumns(30);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel11.add(SIZE, gbc);
        final JPanel panel12 = new JPanel();
        panel12.setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 8;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel3.add(panel12, gbc);
        panel12.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "N（返回生成的版本数）", TitledBorder.LEFT, TitledBorder.TOP, null, null));
        N = new JTextField();
        N.setColumns(30);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel12.add(N, gbc);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return contentPane;
    }

}
